// -----------------------------------------------------------------------
//  <copyright file="GetRoleResourcePageQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-03-01 20:03</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.Entities;
using DaprPlus.Authorization.Domain.Specs;


namespace DaprPlus.Authorization.Application.Queries;

[AuthConfig(typeof(RoleResource), ResourceAccessType.RoleLimit, "GetPage")]
public class GetRoleResourcePageQuery : PageQuery<PageResult<RoleResourceOutDto>>
{ }

public class GetRoleResourcePageQueryHandler(IQueryRepository<RoleResource> queryRepository)
    : IRequestHandler<GetRoleResourcePageQuery, PageResult<RoleResourceOutDto>>
{
    public async Task<PageResult<RoleResourceOutDto>> Handle(GetRoleResourcePageQuery request, CancellationToken cancellationToken)
    {
        var spec = new PageQuerySpecification<RoleResource>(request.PageCondition, request.FilterGroup)
            .AddIncludeEx(m => m.Resource);
        var page = await queryRepository.GetPageAsync<RoleResourceOutDto>(spec, cancellationToken);
        return page;
    }
}

